package com.example.myapplicationndk.worker;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.text.TextUtils;
import android.util.Log;

import com.example.myapplicationndk.R;
import com.example.myapplicationndk.utils.Constants;
import com.example.myapplicationndk.utils.Logd;

import org.jetbrains.annotations.NotNull;

import androidx.annotation.NonNull;
import androidx.work.Worker;
import androidx.work.WorkerParameters;

public class BlurWorker extends Worker {

    private static final String TAG = BlurWorker.class.getSimpleName();

    String resourceUri = getInputData().getString(Constants.KEY_IMAGE_URI);
    private Bitmap mPicture;


    public BlurWorker(@NonNull @NotNull Context context, @NonNull @NotNull WorkerParameters workerParams) {
        super(context, workerParams);
    }

    @NonNull
    @Override
    public Result doWork() {

        Context applicationContext = getApplicationContext();

        try {
            if (TextUtils.isEmpty(resourceUri)) {
                mPicture = BitmapFactory.decodeResource(
                        applicationContext.getResources(),
                        R.mipmap.ic_launcher);
            } else {
                Logd.Logd("asdasdasdadasd");
            }


            // If there were no errors, return SUCCESS
            return Result.success();
        } catch (Throwable throwable) {

            // Technically WorkManager will return WorkerResult.FAILURE
            // but it's best to be explicit about it.
            // Thus if there were errors, we're return FAILURE
            Log.e(TAG, "Error applying blur", throwable);
            return Result.failure();
        }

    }


}